package com.dgut.service.background.dao;

import com.dgut.service.background.entity.Enter;
import com.dgut.service.background.entity.Outs;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface OutsDao extends JpaRepository<Outs, Integer> {
    Page<Outs> findAllByTimesBetween(String date1, String date2, Pageable pageable);

    Page<Outs> findAllByUserOpenidLike(String userOpenid, Pageable pageable);

//    @Query("select o.outId as outId,o.inspectorOpenid as inspectorOpenid,o.userOpenid as userOpenid,o.health as health,o.temp as temp,o.times as times from Outs o,User u where u.name = :username and o.userOpenid = u.openid")
//    Page<Outs> findAllByUsername(@Param("username") String username, Pageable pageable);
    @Query("select new Outs(o.outId,o.inspectorOpenid,o.userOpenid,o.health,o.times,o.temp) from Outs o,User u where u.name = :username and o.userOpenid = u.openid")
    Page<Outs> findAllByUsername(@Param("username") String username, Pageable pageable);

    Page<Outs> findAllByTimesBetweenAndUserOpenidLike(String date1, String date2, String userOpenid, Pageable pageable);

    @Query("select new Outs(o.outId,o.inspectorOpenid,o.userOpenid,o.health,o.times,o.temp) from Outs o,User u where u.name = :username and o.userOpenid = u.openid and o.times between :date1 and :date2")
    Page<Outs> findAllByTimesBetweenAndUsernameLike(@Param("date1") String date1, @Param("date2") String date2, @Param("username")String username, Pageable pageable);

    List<Outs> findAllByUserOpenidLike(String userOpenid);

    @Query("select new Outs(o.outId,o.inspectorOpenid,o.userOpenid,o.health,o.times,o.temp) from Outs o,User u where u.name = :username and o.userOpenid = u.openid")
    List<Outs> findAllByUsername(@Param("username") String username);

    List<Outs> findAllByTimesBetweenAndUserOpenidLike(String date1, String date2, String userOpenid);

    @Query("select new Outs(o.outId,o.inspectorOpenid,o.userOpenid,o.health,o.times,o.temp) from Outs o,User u where u.name = :username and o.userOpenid = u.openid and o.times between :date1 and :date2")
    List<Outs> findAllByTimesBetweenAndUsernameLike(@Param("date1") String date1, @Param("date2") String date2, @Param("username")String username);

    List<Outs> findAllByHealth(String health);

    List<Outs> findAllByTempLessThan(double temp);

    List<Outs> findAllByTempGreaterThan(double temp);

    List<Outs> findAllByTempBetween(double temp1, double temp2);

    List<Outs> findAllByTimesBetween(String date1, String date2);

    List<Outs> findAll();
}
